<template>
  <div>
    <el-row type="flex" justify="end">
      <el-select v-model="currentYear" size="small" style="width:'120px'" @change="dataChange">
        <el-option v-for="item in yearList" :key="item" :value="item">
        </el-option>
      </el-select>
      <el-select v-model="currentMonth" size="small" style="width:'120px';margin-left:10px" @change="dataChange">
        <el-option
          v-for="item in 12"
          :key="item"
          :value="item"
        >
          {{ item }}
        </el-option>
      </el-select>
    </el-row>
    <el-calendar v-model="currentDate">
      <template #dateCell="{date, data}" class="content">
        <div class="date-content">
          <span class="text"> {{ data.day | getDay }}</span>
          <span v-if="isWeek(date)" class="rest">休</span>
        </div>
      </template>
    </el-calendar>
  </div>
</template>

<script>
export default {
  name: 'WorkCalender',
  components: {},
  filters: {
    getDay(value) {
      const day = value.split('-')[2]
      return day.startsWith('0') ? day.substr(1) : day
    }
  },
  props: {
    startDate: {
      type: Date,
      default: () => new Date()
    }
  },
  data() {
    //   得到指定日期，前后5年，通过es5语法
    // const yearList = []
    // for (var i = -5; i <= 5; i++) {
    //   yearList.push(this.startDate.getFullYear() + i)
    // }
    // 2-1 通过array.from+map
    // const yearList=Array.from(new Array(11)).map((t,1)=>this.startDate.getFullYear()+i-5)
    // 通过Array.from+内置map
    const yearList = Array.from(new Array(11), (t, i) => this.startDate.getFullYear() + i - 5)
    return {
      currentYear: this.startDate.getFullYear(),
      currentMonth: this.startDate.getMonth() + 1,
      currentDate: this.startDate,
      yearList
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    dataChange() {
      this.currentDate = new Date(`${this.currentYear}-${this.currentMonth}-01`)
    },
    isWeek(value) {
      return value.getDay() === 6 || value.getDay() === 0
    }
  }
}
</script>

<style lang='scss' scoped>
  ::v-deep .el-calendar-day {
  height:  auto;
 }
  ::v-deep .el-calendar-table__row td, ::v-deep .el-calendar-table tr td:first-child,   ::v-deep .el-calendar-table__row td.prev{
  border:none;
 }
.date-content {
  height: 40px;
  text-align: center;
  line-height: 40px;
  font-size: 14px;
}
.date-content .rest {
  color: #fff;
  border-radius: 50%;
  background: rgb(250, 124, 77);
  width: 20px;
  height: 20px;
  line-height: 20px;
  display: inline-block;
  font-size: 12px;
  margin-left: 10px;
}
.date-content .text{
  width: 20px;
  height: 20px;
  line-height: 20px;
 display: inline-block;

}
  ::v-deep .el-calendar-table td.is-selected .text{
   background: #409eff;
   color: #fff;
   border-radius: 50%;
 }
  ::v-deep .el-calendar__header {
   display: none
 }
</style>
